package com.imooc.api;

import com.imooc.api.intercept.JWTCurrentUserInterceptor;
import com.imooc.api.intercept.SMSInterceptor;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 啊昌
 * @date 2025/9/11 21:43
 * InterceptorConfig 配置类，注册自己定义的拦截器
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
	/**
	 * 在springboot容器中放入拦截器
	 * 验证码拦截器
	 * @return
	 */
	@Bean
	public SMSInterceptor smsInterceptor() {
		return new SMSInterceptor();
	}


	/**
	 * 在springboot容器中放入拦截器
	 * jwt拦截器
	 * @return
	 */
	@Bean
	public JWTCurrentUserInterceptor jwtCurrentUserInterceptor() {
		return new JWTCurrentUserInterceptor();
	}



	/**
	 * 注册拦截器，并且拦截指定的路由，否则不生效
	 *
	 * @param registry
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(smsInterceptor())
				.addPathPatterns("/passport/getSMSCode");

		registry.addInterceptor(jwtCurrentUserInterceptor())
				.addPathPatterns("/**");
	}
}
